{include('Layout/header')}
<div class="row row-bgcolor">
    <div class='col-md-12 content-title'>
        <h3>编辑{$sortMesg['name']}分类</h3>
    </div>
    <div class='col-md-6 content col-md-offset-3'>
        <form action="{\Rexzy::url('admin/asortedit')}">
            <div class="form-group">
                <label for="name">分类名称</label>
                <input type="text" class="form-control" id="name" name="name" value="{$sortMesg['name']}">
            </div>
            <div class="form-group">
                <label for="slugname">分类缩略名</label>
                <input type="text" class="form-control" id="slugname" name="slugname" value="{$sortMesg['slugname']}">
                <p id="slugname_note" class="input-note">分类缩略名用于创建友好的链接形式, 建议使用字母, 数字, 下划线和横杠</p>
            </div>
            <div class="form-group ">
                <label for="parent">父分类</label>
                <select class="form-control select-parent-sort" name="parent" id="parent">
                    <option value="0">不选择</option>
                    {php} 
                    function parentChoice( $id, $sortData, $sortid ) {
                        $sorts = $sortData->selectAll( 'sortid, name, parent, children', "where parent = $id" );
                        foreach ( $sorts as $key => $value ) {
                            if ( $value['sortid'] != $sortid ) {
                                echo "<option value='" . $value['sortid'] . "'>" . $value['name'] . "</option>";
                                if ( $value['children'] > 0 ) {
                                    parentChoice( $value['sortid'], $sortData, $sortid );
                                }
                            }
                        }
                    }
                    parentChoice( 0, $sortData, $sortMesg['sortid'] );
                    {/php}
                    
                </select>
                <p id="slugname_note" class="input-note">此分类将归档在您选择的父级分类下</p>
            </div>
            <div class="form-group ">
                <label for="description">分类描述</label>
                <textarea class="form-control" rows="5" id="description" name="description" >{$sortMesg['description']}</textarea>
                <p id="slugname_note" class="input-note">此文字用于描述分类, 在有的主题中它会被显示</p>
            </div>
            <input type="text" name="sortid" id='sortid' style="display:none;" value="{$sortMesg['sortid']}" />
            <button type="submit" class="btn btn-info edit-user">编辑分类</button>
            <a href="{\Rexzy::url('admin/artsort')}{if $sortMesg['parent'] != 0}echo '?parent='.$parent;{/if}" class="return-userlist">返回{if $sortMesg['parent'] != 0} echo $parentName;{/if}分类列表</a>
        </form>
    </div>
</div>






<script>
    $(function() {
        var parent = "{$parent}";
        $('option').each( function(){
            if ( this.value == parent ) {
                this.selected = "selected";
            }
        });
    });
    
    
    // 用户信息更新成功后跳转函数
    function updateLocation() {
        location = "{\Rexzy::url('admin/artsort')}";
    }
    
    formVerification('form', [
        {
            id:'name',
            required: true,
            errormessage: '请输入分类名',
        },
        {
            id:'slugname',
            required: true,
            errormessage: '请输入缩略名',
        },
        {
            id:'parent',
            required: true,
        },
        {
            id:'description',
            required:false,
        },
        {
            id:'sortid',
            required: true
        }
    ], updateLocation );
</script>
{include('Layout/footer')}